package com.cosmoplat.xikai.business.enums;

import com.cosmoplat.xikai.common.utils.StringUtils;
import lombok.Getter;

@Getter
public enum DeviceRunStatusEnum {

    /**
     * 1.开始生产
     * 2.暂停生产
     * 3.重新生产
     * 4.完工状态获取
     **/
    OFFLINE("0", "离线"),
    START_PRODUCTION("1", "开始生产"),
    SUSPEND_PRODUCTION("2", "暂停生产"),
    REPRODUCTION("3", "重新生产"),
    COMPLETION_STATUS_ACQUISITION("4", "完工状态"),
    ERROR("5", "故障");

    private String code;
    private String name;

    DeviceRunStatusEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getCodeByName(String name) {
        if (StringUtils.isBlank(name)) {
            return null;
        }
        for (DeviceRunStatusEnum value : values()) {
            if (value.getName().equals(name)) {
                return value.getCode();
            }
        }
        return null;
    }

    public static String getNameByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        for (DeviceRunStatusEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value.getName();
            }
        }
        return null;
    }

    /**
     * 工作时间 - 生产中的时间
     * @param deviceStatus
     * @return
     */
    public static boolean workingStatus(String deviceStatus) {
        if (DeviceRunStatusEnum.REPRODUCTION.code.equals(deviceStatus)
                || DeviceRunStatusEnum.START_PRODUCTION.code.equals(deviceStatus)) {
            return true;
        }
        return false;
    }
}
